import axios from 'axios';

//测试
//let baseurl = 'https://shanzhuan.autocloudchain.com/api/';
// let baseurl = 'https://tp6.shanzhuanvip.com/api/'
//线上
//let baseurl = 'https://www.shanzhuanvip.com/api/';

// 20210302 更新
// let baseurl = 'https://www.shangzhong.vip/api/';

// 20210706 
let baseurl = 'http://tomi.pingyiyouxuan.com/api/'

export function axiosPost(url, option, callback) {
  if (localStorage.getItem('userinfo')) {
    option.token = JSON.parse(localStorage.getItem('userinfo')).token || '';
  }
  axios({
    method: 'post',
    url: baseurl + url,
    data: option,
  })
    .then((response) => {
      if (response.status === 200) {
        return callback(response.data);
      }
    })
    .catch((error) => {
      console.log(error);
    });
}

export function axiosPostnotoken(url, option, callback) {
  axios({
    method: 'post',
    url: baseurl + url,
    data: option,
  })
    .then((response) => {
      if (response.status === 200) {
        return callback(response.data);
      }
    })
    .catch((error) => {
      console.log(error);
    });
}

export function axiosPostupload(url, option, callback) {
  axios({
    method: 'post',
    url: baseurl + url,
    data: option,
  })
    .then((response) => {
      if (response.status === 200) {
        return callback(response.data);
      }
    })
    .catch(() => {
      return callback();
    });
}
